package com.myproject.thread.lock;

public class Test3 {

    public static volatile Boy boy = new Boy();
    public static volatile Girl girl = new Girl();
    public static volatile Person p1 = null;
    public static volatile Person p2 = null;
    public static void main(String[] args) {

        p1 = boy;
        new Thread(()->{
            p2=p1;
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread()+" "+p2.getGender());
        }).start();

        new Thread(()->{
            p1=girl;
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread()+" "+p2.getGender());
        }).start();

    }
}
